<include file="public/header"/>
</head>
<body>
<div class="wrap js-check-wrap">
    <form method="post" class="js-ajax-form" action="{:cmf_plugin_url('Modules://AdminColumn/listorders')}">
        <table class="table table-hover table-bordered table-list">
            <thead>
            <tr>
                <th width="16">
                </th>
                <th width="50">ID</th>
                <th>分类名称</th>
            </tr>
            </thead>
            <tbody>
            {$categories_tree}
            </tbody>
        </table>
    </form>
</div>
<script src="__PLUGIN_TMPL__/public/assets/js/admin.js"></script>
<script>
    $('.data-item-tr').click(function (e) {
        var $this = $(this);
        if ($(e.target).is('input')) {
            if ($this.is(':checked')) {
                $this.prop('checked', false);
            } else {
                $(this).parent().find('tr').siblings('tr').prop('checked', false);
                $this.prop('checked', true);
            }
        }else {
            var $input = $this.find('input');
            if ($input.is(':checked')) {
                $input.prop('checked', false);
            } else {
                $('.data-item-tr td input').prop('checked', false);
                $input.prop('checked', true);
            }
        }
        //确认选择 - 如果需要快速选择栏目，就解开下面2段被*(星号)注释掉的代码
        /*var selectedCategories = confirm();*/
//        if (selectedCategories.selectedCategoriesId.length == 0) {
//            parent.layer.msg('请选择分类');
//            return;
//        }
        /*var fieldname = "<?php echo !empty($_GET['fieldname']) ? $_GET['fieldname'] : 'input';?>";
        parent.$('#js-categories-id-'+fieldname).val(selectedCategories.selectedCategoriesId.join(','));
        parent.$('#js-categories-name-'+fieldname).val(selectedCategories.selectedCategoriesName.join(' '));
        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        parent.layer.close(index);*/

    });

    function confirm() {
        var selectedCategoriesId   = [];
        var selectedCategoriesName = [];
        var selectedCategories     = [];
        $('.js-check:checked').each(function () {
            var $this = $(this);
            selectedCategoriesId.push($this.val());
            selectedCategoriesName.push($this.data('name'));

            selectedCategories.push({
                id: $this.val(),
                name: $this.data('name')
            });
        });
        return {
            selectedCategories: selectedCategories,
            selectedCategoriesId: selectedCategoriesId,
            selectedCategoriesName: selectedCategoriesName
        };
    }
</script>
</body>
</html>